var formId = "";
// 获取属于指定弹出的二级id值
var textareaId = "";
// 获取验证码
var clickPhoneCodeNum = 0;
function getPhoneCode(className) {
    if (clickPhoneCodeNum == 0) {
        clickPhoneCodeNum = 1;
        setTimeout(function () {
            clickPhoneCodeNum = 0;
        }, 3000);
        //点击按钮
        var _getCode = $(className).find(".get-code");
        var _tel = $(className).find('input[name="tel"]').val();
        var _reg = /^1[3,4,5,6,7,8,9]\d{9}$/;
        if (_tel == "") {
            layer.msg("请输入您的电话");
            return;
        }
        if (!_reg.test(_tel)) {
            layer.msg("请输入正确的手机号码");
            return;
        }
        var verificationCode = {
            customerPhone: doEncrypt(_tel),
            imageCode: "",
            whetherVerifyImageCode: false,
        };
        getCodeApi(verificationCode, _getCode);
    }else{
        layer.msg("请勿频繁操作！");
    }

}
// 一级表单提交
function formSubmit(className) {
    var clickNum = 0;
    $("." + className).on("click", ".submit_btn", function () {
        if (clickNum == 0) {
            clickNum = 1;
            setTimeout(function () {
                clickNum = 0;
            }, 3000);
            var secondaryData = {};
            var _name = $(this).parents("form").find('input[name="name"]').val();
            var _qymc = $(this).parents("form").find('input[name="qymc"]').val();
            var _tel = $(this).parents("form").find('input[name="tel"]').val();
            var _code = $(this).parents("form").find('input[name="msgCode"]').val();
            var _cpmc = "个体工商户注册";
            var _cpmcCode = "FL20211208186876";
            var _city = $(this).parents("form").find('.city_select option:selected').attr("data-name");
            var _cityCode = $(this).parents("form").find('.city_select option:selected').val();
            var _reg = /^1[3,4,5,6,7,8,9]\d{9}$/;
            if (!_name) {
                layer.msg("请输入您的称呼");
                return;
            }else{
                secondaryData.name = _name;
            }
            if (_tel == "") {
                layer.msg("请输入您的电话");
                return;
            }
            if (!_reg.test(_tel)) {
                layer.msg("请输入正确的手机号码");
                return;
            }
            if (!_code) {
                layer.msg("请输入验证码");
                return;
            }
            if (!_qymc) {
                layer.msg("请输入公司名称");
                return;
            }else{
                secondaryData.qymc=_qymc
            }
            if (!_city) {
                layer.msg("请选择所在城市");
                return;
            }else {
                secondaryData.city = _city;
            }


            // 生成forId * 当前data-手机-随机数 *
            formId = getDate() - _tel - Math.floor(Math.random() * 1000 + 10) + "";
            // 一级表单需要的参数
            var formMessage = {
                areaCode: _cityCode, // 城市code
                areaName: _city, //城市名称
                customerName: _name, // 客户姓名
                customerPhone: doEncrypt(_tel), // 客户手机号
                deviceType: "PC", // 设备端口
                formId: formId, // formID
                keyword: "",
                remark: "", // 备注
                requireCode: [_cpmcCode], // 需求编码
                requireName: [_cpmc], // 需求名称
                sourceUrl: window.location.href+"?utm_medium=seo&utm_source=bdpc",//URL
                webType: "zy3",
                verificationCode: _code // 验证码code
            };
            // 提交一级表单并判断成功清空值
            if (consultFormApi(formMessage) == 200) {
                // 二级表单需要的参数
                $("input[name='tel']").val("");
                $("input[name='msgCode']").val("");
                // 必填 dataJSON,forID
                var secondaryFormData = {
                    dataJson: secondaryData,
                    formId: formId
                };
                if (JSON.stringify(secondaryData) !== "{}") {
                    // dataJson需要转化为JSON格式，"xxx":"xxx"
                    secondaryFormData.dataJson = JSON.stringify(secondaryFormData.dataJson);
                } else {
                    layer.msg("请至少选中一项");
                    return;
                }
                // 提交二级表单并判断成功清空值
                if (secondaryFormApi(secondaryFormData) == 200) {
                    secondaryData = {};
                }
            }
        } else {
            layer.msg("请勿频繁操作！");
        }
    });
}
formSubmit("messageForm");
/*法律表单*/
